<?php

namespace App\Libs\Company\SheetTemplateHandler;

use App\Exceptions\AppException;
use App\Models\SheetTemplate;
use App\Models\SubTask;
use App\Models\Task;

class Manager
{
    public static function createReportHandler(SheetTemplate $model, SubTask $subTask = null): \App\Libs\Company\SheetTemplateHandler\Report\AbstractTemplate
    {
        $class = '';
        if ($model->type == SheetTemplate::TYPE_REPORT) {
            $class = 'App\Libs\Company\SheetTemplateHandler\Report\Template' . $model->id;
        }
        if (!class_exists($class)) {
            throw new \Exception('初始化模板处理类异常, id: ' . $model->id);
        }
        return new $class($model, $subTask);
    }

    public static function createAggregateHandler(SheetTemplate $model, Task $task = null): \App\Libs\Company\SheetTemplateHandler\Aggregate\AbstractTemplate
    {
        $class = '';
        if ($model->type == SheetTemplate::TYPE_AGGREGATE) {
            $class = 'App\Libs\Company\SheetTemplateHandler\Aggregate\Template' . $model->id;
        }
        if (!class_exists($class)) {
            throw new \Exception('初始化模板处理类异常, id: ' . $model->id);
        }
        return new $class($model, $task);
    }

    public static function export($univerData, $name = 'sheet')
    {
        return Export::export($univerData, $name);
    }
}
